'use strict';

const getFavorites = require('./get-favorites');
const addFavorite = require('./add-favorite');
const removeFavorite = require('./remove-favorite');
const checkFavorite = require('./check-favorite');

exports.main = async (event, context) => {
  const { action, data } = event;
  
  try {
    switch (action) {
      case 'get-favorites':
        return await getFavorites.main(event, context);
      case 'add-favorite':
        return await addFavorite.main(event, context);
      case 'remove-favorite':
        return await removeFavorite.main(event, context);
      case 'check-favorite':
        return await checkFavorite.main(event, context);
      default:
        return {
          code: 400,
          message: '未知的操作类型',
          data: null
        };
    }
  } catch (error) {
    return {
      code: 500,
      message: '服务器内部错误',
      data: null
    };
  }
};
